package com.goodfather.textbook.youdao.pad.ui;

import android.content.Intent;
import android.os.Handler;
import android.text.TextUtils;

import androidx.annotation.Nullable;

import com.goodfather.textbook.youdao.pad.util.StringUtil;
import com.goodfather.textbook.youdao.pad.util.UrlParse;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.goodfather.textbook.youdao.pad.R;
import com.goodfather.textbook.youdao.pad.bean.Http;
import com.goodfather.textbook.youdao.pad.bean.UserData;
import com.goodfather.textbook.youdao.pad.bean.UserManager;
import com.goodfather.textbook.youdao.pad.network.ApiConstant;
import com.goodfather.textbook.youdao.pad.network.JsonCallBack;
import com.goodfather.textbook.youdao.pad.util.JumpUtil;
import com.goodfather.textbook.youdao.pad.util.L;
import com.goodfather.textbook.youdao.pad.util.ToastUtil;
import com.goodfather.textbook.youdao.pad.weight.ToolbarActivity;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @Author: zhou
 * @CreateDate: 2021/11/22
 */
public class SplashActivity extends ToolbarActivity {

    @Override
    protected int getLayoutId() {
        return R.layout.activity_splash;
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        mIntent = intent;
    }

    @Override
    protected void initViews() {
        String url = mIntent.getStringExtra("url");
        if (TextUtils.isEmpty(url)) {
            ToastUtil.show("无透传参数");
            return;
        }
        try {
            String s = "goodfather://thirdpartyOpen?providerClickMode=7&providerBookName=PEP-25- EN&providerBookPage=36&providerBookUnitId=2505&providerSentenceId=456&providerUserID=ce1db06cd4910df593b8da26ab7553c9";
            String decodeUrl = URLDecoder.decode(url, "utf-8");
            final String providerClickMode = UrlParse.getValueByName(decodeUrl, "providerClickMode");
            final String providerBookName = UrlParse.getValueByName(decodeUrl, "providerBookName");
            final String providerBookPage = UrlParse.getValueByName(decodeUrl, "providerBookPage");
            final String providerBookUnitId = UrlParse.getValueByName(decodeUrl, "providerBookUnitId");
            //有道用户 Id
            final String providerUserID = UrlParse.getValueByName(decodeUrl, "providerUserID");
            //指定句子ID值，非必传，用于指读功能
            final String providerSentenceId = UrlParse.getValueByName(decodeUrl, "providerSentenceId");
            jumpTargetBook(providerClickMode, providerBookName, providerBookPage, providerBookUnitId, providerUserID, providerSentenceId);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    private void jumpTargetBook(String providerClickMode, String providerBookName, String providerBookPage, String providerBookUnitId, String providerUserID, String providerSentenceId) {
        if (providerClickMode.equals("7")) {
            if (!StringUtil.isEmpty(providerBookName)) {
                String[] params = providerBookName.split("-");
                String publishingId = params[0];
                String bookId = params[1];
                String subjectId = params[2];
                if (StringUtil.isEmpty(publishingId) || StringUtil.isEmpty(bookId) || StringUtil.isEmpty(subjectId)) {
                    return;
                }
                if (params.length == 3) {
                    if (!TextUtils.isEmpty(publishingId) && !TextUtils.isEmpty(bookId) && !TextUtils.isEmpty(subjectId) && !TextUtils.isEmpty(providerBookUnitId) && !TextUtils.isEmpty(providerUserID) && !TextUtils.isEmpty(providerBookPage)) {
                        JumpUtil.gotoBookDetail(SplashActivity.this, providerClickMode, bookId, publishingId, subjectId, providerBookUnitId, providerUserID);
                    }
                } else {
                    L.d("providerBookName拼接参数有误");
                }
            }
        } else {
            L.d("providerClickMode非有效参数");
        }
    }


    @Override
    protected void initData() {

    }
}
